<template>
	<view>
		<view style="background-color: #2DBB55;" :style="{height:bgHeight}">
			<view
				style="display: flex;flex-direction: row;justify-content: space-between;margin-left: 20rpx;margin-right: 20rpx;"
				:style="{paddingTop:topHeigh}">
				<u-icon name="arrow-left" size="28" color="#ffffff" @click="finish"></u-icon>
				<text style="color: #ffffff;font-size: 36rpx;">我的信息</text>
				<text style="height: 28rpx;width: 28rpx;"></text>
			</view>
		</view>
		<view style="margin-left: 20rpx;margin-right: 20rpx;">
			<u-input customStyle="height: 108rpx;" font-size="32rpx" border="bottom" v-model="info.name">
				<text slot="prefix" style="font-size: 32rpx;">*您的称呼：</text>
			</u-input>
			<u-input customStyle="height: 108rpx;" font-size="32rpx" border="bottom" v-model="phoneRes"
				disabledColor="#ffffff" disabled>
				<text slot="prefix" style="font-size: 32rpx;">您的手机号：</text>
			</u-input>
			<u-input customStyle="height: 108rpx;" font-size="32rpx" border="bottom" v-model="info.company">
				<text slot="prefix" style="font-size: 32rpx;">您的企业名：</text>
			</u-input>
			<u-text customStyle="margin-top: 20rpx;margin-left: 6rpx;" size="32rpx" text="企业简介"></u-text>
			<u--textarea customStyle="margin-top: 20rpx;" height="260rpx" :maxlength="-1"
				placeholder="举例：专业回收各种工厂废钢铁、铜、 铝、不锈钢，铝合金等各种废金属" v-model="info.info">
			</u--textarea>
		</view>
		<view
			style="position: fixed;bottom: 15rpx;display: flex;justify-content: space-between;flex-direction: row;width: 100%;">
			<u-button customStyle="width: 333rpx;margin-bottom: 80rpx;" type="info" plain @click="finish">取消</u-button>
			<u-button customStyle="width: 333rpx;margin-bottom: 80rpx;" type="success" @click="saveInfo">保存</u-button>
		</view>
	</view>
</template>

<script>
	import {
		ownInfoSave,
		ownInfo
	} from '@/api/my.js';
	export default {
		data() {
			return {
				// 获取整个导航栏高度
				bgHeight: this.ToolClass.getNavtionBarAllHeight(),
				// 获取微信胶囊高度
				topHeigh: this.ToolClass.getWXJNHeight(),
				info: {
					name: "",
					company: "",
					phone: "",
					info: "",
					app_id: "wx07c6c7321f12486f"
				},
			}
		},
		computed: {
			phoneRes() {
				const reg = /^(\d{3})\d{4}(\d{4})$/
				return this.info.phone.replace(reg, '$1****$2')
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			async getData() {
				ownInfo().then(res => {
					this.info = res
				})
			},
			async saveInfo() {
				if (this.info.name == "") {
					uni.showToast({
						title: '请输入您的称呼',
						icon: 'none'
					})
					return
				}
				ownInfoSave(this.info).then(res => {
					this.finish()
				})
			},
			finish() {
				uni.navigateBack()
			}
		}
	}
</script>

<style>
</style>